﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoreRay
{
    public class Sphere : ParametricSurface
    {
        public Sphere() : this(1.0f)
        {
        }

        public Sphere(float radius)
        {
            this.Radius = radius;
            this.Generate();
        }

        public float Radius
        {
            get;
            set;
        }

        protected override Vector3 ComputeVertexPosition(float s, float t)
        {
            float x = this.Radius * (float) System.Math.Sin(MathUtility.PI * t) * (float) System.Math.Cos(MathUtility.PI2 * s);
            float y = this.Radius * (float) -System.Math.Cos(MathUtility.PI * t);
            float z = this.Radius * (float) System.Math.Sin(MathUtility.PI * t) * (float) System.Math.Sin(MathUtility.PI2 * s);

            return new Vector3(x, y ,z);
        }

        protected override Vector3 ComputeVertexNormal(float s, float t)
        {
            float x = (float) System.Math.Sin(MathUtility.PI * t) * (float)System.Math.Cos(MathUtility.PI2 * s);
            float y = (float) -System.Math.Cos(MathUtility.PI * t);
            float z = (float) System.Math.Sin(MathUtility.PI * t) * (float)System.Math.Sin(MathUtility.PI2 * s);

            return new Vector3(x, y, z).Normalize();
        }
    }
}
